//
//  ContractInfoGrabViewModel.m
//  Jyxt
//
//  Created by 刘日 on 17/5/31.
//  Copyright © 2017年 DaLian Rental Housing Management. All rights reserved.
//

#import "ContractInfoGrabViewModel.h"
#import "NetTool.h"
#import <MJExtension.h>
#import "UserCenterViewModel.h"
#import <LemonBubble.h>
#import "CommonViewModel.h"

@implementation ContractInfoGrabViewModel

+ (void)applyContractInfoWithNo: (NSString *)no
                        remarks: (NSString *)remarks
                         photos: (NSArray<UIImage *> *)photos
                    whenSuccess: (void (^)())success
                         failed: (void (^)(NSString *reason))failed{
    NSMutableDictionary *photosDic = [NSMutableDictionary new];
    for (UIImage *image in photos)
        photosDic[[NSString stringWithFormat: @"Photo%lu" , (unsigned long)[image hash]]] = image;
    [[LKFreeCtrl getTopViewController] showRoundProgressWithTitle: @"正在上传中"];
    [NetTool uploadWithUrl: APIURL(API_CONTRACT_INFO_UPLOAD)
                parameters: @{@"data" : @{@"contractNo" : no , @"remark" : remarks}.mj_JSONString , @"utoken" : [UserCenterViewModel getLocalUToken]}
                      data: photosDic
                 onSuccess:^(NSDictionary *response) {
                    [CommonViewModel checkResponseBody: response whenSuccess:^{
                        success();
                    } failed:^(NSString *reason) {
                        failed(reason);
                    }];
                 }
                   onError:^(NSError *error) {
                       failed(@"发布失败，无法连接到服务器");
                   }];
}



@end
